package util;

import javax.servlet.http.HttpServletRequest;

/**
 * @author winkyle
 * @date 2018/06/22
 * @description 路径获取生成工具类
 */
public class PathUtil {
	
	/**
	 * @description 获取服务器的访问路径;协议名称://服务器名称:端口/web项目
	 * @param httpServletRequest
	 * @return
	 */
	public static String getAccessPath(HttpServletRequest httpServletRequest){
		String path = httpServletRequest.getScheme()+"://"+httpServletRequest.getServerName()+":"+
				httpServletRequest.getServerPort()+httpServletRequest.getContextPath()+"/";
		return path;
	}

	/**
	 * @description 获取web项目的绝对路径;
	 * @param httpServletRequest
	 * @return
	 */
	public static String getAbsolutePath(HttpServletRequest httpServletRequest){
		String path = httpServletRequest.getSession().
                getServletContext().getRealPath("/");
		return path;
	}
}
